package abq2.jic.jic.plugin.operate.teacherEvaluate;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.form.gpt.IGPTAction;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;

import java.util.HashMap;
import java.util.Map;

public class EvaluateConclude implements IGPTAction {
    @Override
    public Map<String, String> invokeAction(String action, Map<String, String> params) {
        Map<String , String> result = new HashMap<>();
        if ("GET_All_Evaluate".equalsIgnoreCase(action)) {
            //获取DynamicObject列表，即获取学生的单据头的信息
            DynamicObject[] dys = BusinessDataServiceHelper.load("abq2_evaluate_result", //反馈单据
                    "abq2_teacher_name," +         //教师姓名
                            "abq2_teacherid," +    //教工号
                            "abq2_evaluate_score," + //分数
                            "abq2_evaluate_context",     //评价信息
                    (new QFilter("abq2_teacher_name", QCP.is_notnull, null)).toArray());

            //创建一个JsonArray
            JSONArray jsonArray = new JSONArray();
            for (DynamicObject dynamicObject : dys) {
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("teacherName", dynamicObject.getString("abq2_teacher_name"));
                jsonObject.put("teacherId",dynamicObject.getString("abq2_teacherid"));
                jsonObject.put("evaluateScore",dynamicObject.getString("abq2_evaluate_score"));
                jsonObject.put("evaluateContext",dynamicObject.getString("abq2_evaluate_context"));
                jsonArray.add(jsonObject);
            }

            System.out.println(jsonArray.toJSONString());
            //加入resultDynamicObject参数，将JsonArray加入到这个参数当中，然后返回
            result.put("evaluateContext", jsonArray.toJSONString());
        }
        return result;
    }
}
